package com.chinadci.smartcommunitysystembackstage.controller;


import com.chinadci.smartcommunitysystembackstage.service.ScsActivityService;
import com.chinadci.smartcommunitysystembackstage.service.ScsFeedbackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Code Duck
 * @since 2021-04-13
 */
@CrossOrigin
@RestController
@Api("建业E家")
public class ScsFeedbackController {
    @Autowired
    private ScsFeedbackService service;

    //显示全部意见反馈
    @ApiOperation(value = "显示全部意见反馈")           //swagger
    @ApiImplicitParam(name = "title",value = "投诉标题")       //表明要传入的参数
    @RequestMapping(value = "/api/yjfkfind",method = RequestMethod.GET)
    public Map Finds(String title){
        Map<String,Object> map=new HashMap<>();
        map.put("data",service.Find(title));
        return map;
    }

    //处理意见反馈
    @ApiOperation(value = "处理意见反馈")           //swagger
    @ApiImplicitParam(name = "id",value = "意见反馈编号")       //表明要传入的参数
    @RequestMapping(value = "/api/yjfkupdate",method = RequestMethod.POST)
    public Map Update(int id){
        Map<String,Object> map=new HashMap<>();
        if (service.Finds(id).getFState()==1){
            map.put("state",1);     //1是正在处理中
            return map;
        }else if (service.Finds(id).getFState()==2){
            map.put("state",2);     //2是已经处理过
            return map;
        }
        map.put("state",0);
        map.put("data",service.Update(id));
        return map;
    }
}
